<template>
  <el-form>
    <el-form-item label="oldPassword">
      <el-input show-password v-model.trim="user.oldPassword"/>
    </el-form-item>
    <el-form-item label="newPassword">
      <el-input show-password v-model.trim="user.newPassword"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submit">Update</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { updatePassword } from '@/api/admin/user'

export default {
  props: {
    user: {
      type: Object,
      default: () => {
        return {
          oldPassword: '',
          newPassword: ''
        }
      }
    }
  },
  methods: {
    submit() {
      updatePassword({
        oldPassword: this.user.oldPassword,
        newPassword: this.user.newPassword
      }).then(() => {
        this.$message({
          message: 'User information has been updated successfully',
          type: 'success',
          duration: 5 * 1000
        })
      })
    }
  }
}
</script>
